﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Paradox.Models;
using Paradox.Models.DataModels;


namespace Paradox.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        StoryRepository repo = new StoryRepository();

        public ActionResult Index()
        {
            var stories = repo.GetRecentStories(5);


            return View(stories);
        }

        //
        // GET: /Home/Story/5

        public ActionResult Story(int id)
        {
            var stories = repo.getStory(id);
            return View("Story", stories);
        }

        //
        // GET: /Home/Create
        [Authorize]
        public ActionResult Create()
        {
            return View();
        }


        // POST: /Home/Create
        [Authorize]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /Home/Edit/2
        [Authorize(Roles="elevateduser")]
        public ActionResult Edit(int id)
        {

            return View();
        }

        //
        // POST: /Home/Edit/2
        [Authorize(Roles = "elevateduser")]
        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Edit(int id, Story story)
        {
            try
            {


                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        public ActionResult About()
        {
            return View("About");

        }


        public ActionResult Contact()
        {

            return View("Contact");
        }



        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Contact(FormCollection contactForm)
        {

            return View("EmailSent");
        }


    }
}
